# the minimum version of CMake.
cmake_minimum_required(VERSION 3.4.1)
project(XComponent)

set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
add_definitions(-DOHOS_PLATFORM)

# -----> user1_start
set(RKNN_LIB ${NATIVERENDER_ROOT_PATH}/../../../libs/${OHOS_ARCH})
set(OPENCV_LIB_PATH ${NATIVERENDER_ROOT_PATH}/../../../libs/${OHOS_ARCH})
set(NCNN_LIB_DIR ${NATIVERENDER_ROOT_PATH}/../../../libs/${OHOS_ARCH})
set(NCNN_INCLUDE_DIR ${NATIVERENDER_ROOT_PATH}/ncnn)
set(GLSLANG_INCLUDE_DIR ${NATIVERENDER_ROOT_PATH}/glslang)
link_directories(${OPENCV_LIB_PATH})

set(CMAKE_BUILD_WITH_INSTALL_RPATH On)

set(BUILD_TESTS OFF)
set(BUILD_PERF_TESTS OFF)
set(BUILD_EXAMPLES OFF)
set(BUILD_DOCS OFF)
set(WITH_OPENCL ON)

# 按需选择要编译的opencv module, 与target_link_libraries中的一致
# set(BUILD_LIST core imgproc imgcodecs highgui video videoio)

# 设置编译类型为Release
set(CMAKE_BUILD_TYPE RELEASE)
set(CMAKE_CXX_FLAGS_RELEASE -g0 )
# -----> user1_end

include_directories(
    ${NATIVERENDER_ROOT_PATH}
    ${NATIVERENDER_ROOT_PATH}/include
    ${NCNN_INCLUDE_DIR}
    ${GLSLANG_INCLUDE_DIR}
)

# 添加NCNN库
add_library(ncnn STATIC IMPORTED)
#设置目标属性 对应目标为ncnn静态库导入
set_target_properties(ncnn PROPERTIES
    IMPORTED_LOCATION ${NCNN_LIB_DIR}/libncnn.a)
#添加glslang库
add_library(glslang STATIC IMPORTED)
#设置目标属性 对应目标为glslang静态库文件导入
set_target_properties(glslang PROPERTIES
    IMPORTED_LOCATION ${NCNN_LIB_DIR}/libglslang.a)

add_library(nativerender SHARED
    render/egl_core.cpp
    render/plugin_render.cpp
    imagedeal/imagedeal.cpp
    imagedeal/postprocess.cpp
    manager/plugin_manager.cpp
    nle/nle_file.cpp
    napi_init.cpp
)

find_library(
    # Sets the name of the path variable.
    EGL-lib
    # Specifies the name of the NDK library that
    # you want CMake to locate.
    EGL
)

find_library(
    # Sets the name of the path variable.
    GLES-lib
    # Specifies the name of the NDK library that
    # you want CMake to locate.
    GLESv3
)

find_library(
    # Sets the name of the path variable.
    hilog-lib
    # Specifies the name of the NDK library that
    # you want CMake to locate.
    hilog_ndk.z
)

find_library(
    # Sets the name of the path variable.
    libace-lib
    # Specifies the name of the NDK library that
    # you want CMake to locate.
    ace_ndk.z
)

find_library(
    # Sets the name of the path variable.
    libnapi-lib
    # Specifies the name of the NDK library that
    # you want CMake to locate.
    ace_napi.z
)

find_library(
    # Sets the name of the path variable.
    libuv-lib
    # Specifies the name of the NDK library that
    # you want CMake to locate.
    uv
)

target_link_libraries(nativerender PUBLIC
    ${EGL-lib}
    ${GLES-lib}
    ${hilog-lib}
    ${libace-lib}
    ${libnapi-lib}
    ${libuv-lib}
    librawfile.z.so
    opencv_core
    opencv_imgcodecs
    opencv_imgproc
    opencv_highgui
    opencv_video
    opencv_videoio
    PRIVATE
    libhilog_ndk.z.so ncnn glslang
)
